package pack0901;

public class DemoB {
    public static void main(String[] args) {
        DemoB2 db2 = new DemoB2();
        DemoB3 db3 = new DemoB3();
        Thread t2 = new Thread(db2);
        Thread t3 = new Thread(db3);
        t2.start();
        t3.start();
    }
}
class DemoB1{
    public static final Object obj1 = new Object();
    public static final Object obj2 = new Object();
}
class DemoB2 implements Runnable{
    @Override
    public void run() {
        while (true){
            synchronized (DemoB1.obj1){
                System.out.println("aaa1");
                synchronized (DemoB1.obj2){
                    System.out.println("bbb1");
                }
            }
        }
    }
}
class DemoB3 implements Runnable{
    @Override
    public void run() {
        while(true){
            synchronized (DemoB1.obj2){
                System.out.println("aaa2");
                synchronized (DemoB1.obj1){
                    System.out.println("bbb2");
                }
            }
        }
    }
}
